package kgame5.kgfw.gbook {
import kgame5.kutil.KEvent;

import flash.utils.Dictionary;

/**
 * @author kangkai
 * 管理各个页面切换动画的,持有各个页面的引用mc,而不管里面具体是什么
 */
public class GameBookComp {
	
	//dict[pageID]=pageComp
	private var dict_pages:Dictionary;
	
	private var curPage:PageComp;
	
	public function GameBookComp(){
		dict_pages=new Dictionary();
	}
	
	public function addPage(pageComp:PageComp):void{
		dict_pages[pageComp.getID()]=pageComp;
	}
	public function findPage(pageID:int):PageComp{
		return dict_pages[pageID];
	}
	
	public function turnPage(pageID:int):void{
		//T.p("turnPage",pageID);
		
		//老的release
		if(curPage!=null){
			curPage.onRelease();
			//老的不显示
			curPage.getMC().visible=false;
			
			curPage.dispatchEvent(new KEvent(PageComp.EVENTTYPE_AFTER_RELEASE));
		}
		
		//新的create
		var nextPage:PageComp=findPage(pageID);
		if(nextPage==null){
			throw new Error("!无此pageID:"+pageID);
		}
		nextPage.onCreate();
		
		//新的显示	
		nextPage.getMC().visible=true;
		
		nextPage.dispatchEvent(new KEvent(PageComp.EVENTTYPE_AFTER_CREATE));
		
		//记录当前的页面
		curPage=nextPage;
		
	}
	
	public function hide():void{
		for each(var pageComp:PageComp in dict_pages){
			pageComp.getMC().visible=false;
		}
	}
	
	public function show():void{
		for each(var pageComp:PageComp in dict_pages){
			pageComp.getMC().visible=true;
		}
	}
	
}//end of class
}
